python从字典中找值 您所在的位置:网站首页 python value方法 python从字典中找值

python从字典中找值

#python从字典中找值| 来源: 网络整理| 查看: 265

在 Python 中,可以使用下面的代码来从字典中找值:

dictionary = {'key1': 'value1', 'key2': 'value2'} # 方法一 value = dictionary['key1'] print(value) # 输出 'value1' # 方法二 value = dictionary.get('key1') print(value) # 输出 'value1'

在这里,我们使用两种方法从字典 dictionary 中找到键为 'key1' 的值。第一种方法是使用下标访问,第二种方法是使用 get() 方法。如果键



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有